package com.fucking.great.context.common.job;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.fucking.great.context.GreatMain;
import com.fucking.great.context.TxnContext;
import org.quartz.*;

import java.time.LocalDateTime;
import java.util.Locale;

public class TxnContextJob implements Job {
    public static final Log logger = LogFactory.get();
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        //
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        String systemName = jobDataMap.getString("systemName");
        String path = jobDataMap.getString("path");
        //
        TxnContext texContext = TxnContext.getContext();
        texContext.setLogger(logger);
        texContext.setType("job");
        texContext.setUrl("/job/"+path); // 执行的路径。
        texContext.setClientIp(TxnContext.SERVICE_IP);
        texContext.setLocale(Locale.getDefault());
        //
        texContext.setPath(path);
        texContext.setAppid(systemName);
        texContext.setSystemName(systemName);
        //
        texContext.putAll(jobDataMap);
        //
        Object result = GreatMain.doService(texContext);
        //
        System.out.println(result);
    }

}